package com.allenkerr.controller;

import com.allenkerr.service.ProductService;
import com.allenkerr.vo.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by 小柯(Allen Kerr) on 17.5.2 9:09.
 */
@Controller
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/search")
    public String search(String queryString, String catalog_name, String price, String sort, Integer page, Model model)
            throws Exception {

        //获取查询结果
        ResultModel result = productService.query(queryString, catalog_name, price, sort, page);

        //返回结果
        model.addAttribute("result", result);
        model.addAttribute("queryString", queryString);
        model.addAttribute("catalog_name", catalog_name);
        model.addAttribute("price", price);
        model.addAttribute("sort", sort);

        //返回页面
        return "product_list";
    }

}
